package com.geping.etl.common.controller;

import com.geping.etl.common.entity.DataDictionary;
import com.geping.etl.common.service.DataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/***
 * 数据字典控制器
 * @author liang.xu
 * @date 2021.4.29
 */
@RestController
public class DataDictionaryController {

    @Autowired
    private DataDictionaryService dataDictionaryService;

    //查询数据字典
    @GetMapping("/queryDataDictionary")
    public List<DataDictionary> queryataDictionary(Integer type) {
        DataDictionary dataDictionary = new DataDictionary();
       // dataDictionary.setCode("");
       // dataDictionary.setText("--请选择--");
        List<DataDictionary> list = dataDictionaryService.findByType(type);
        list.add(0,dataDictionary);
        return list;
    }

    //不必填字段查询数据字典
    @GetMapping("/queryDataDictionary_not")
    public List<DataDictionary> queryDataDictionary_not(Integer type) {
        DataDictionary dataDictionary = new DataDictionary();
        dataDictionary.setCode("");
        dataDictionary.setText("--请选择--");
        List<DataDictionary> list = dataDictionaryService.findByType(type);
        list.add(0,dataDictionary);
        return list;
    }

    //带参数查询数据字典
    @GetMapping("/queryDataDictionary_param")
    public List<DataDictionary> queryDataDictionary_param(HttpServletRequest request, Integer type) {
        DataDictionary dataDictionary = new DataDictionary();
        String q = request.getParameter("q");
        // dataDictionary.setCode("");
        // dataDictionary.setText("--请选择--");
        List<DataDictionary> list = dataDictionaryService.findByType_param(type,q);
        list.add(0,dataDictionary);
        return list;
    }
}